import http2 from 'node:http2'
import fs from 'node:fs'

// 在 02目录下运行 node app.js  否则上下文不对，读取下面的文件目录不对
const options = {
  key: fs.readFileSync('./server.key'),
  cert: fs.readFileSync('./server.crt')
}


const server = http2.createSecureServer(options, (req, res) => {

  console.log(req.url);
  if (req.url === '/') {
    res.stream.respondWithFile('./public/index.html', {
      'content-type': 'text/html',
      'status': 200
    })

    return
  }

  if(req.url === '/test.css') {
    res.stream.respondWithFile('./public/test.css', {
      'status': 200
    })
    return
  }

  if(req.url === '/test.js') {
    res.stream.respondWithFile('./public/test.js', {
      'status': 200
    })
    return
  }

  if(req.url === '/favicon.ico') {
    res.end()
  }
})

server.listen(5000, () => {
  console.log('https://localhost:5000');
})
